{% extends "smErp/base.html" %}

{% block css_style %}
    {% load staticfiles %}
    <link href="{% static 'smErp/css/brand_info.css' %}" type="text/css" rel="stylesheet">
    <link href="{% static 'smErp/assets/dropzone/basic.min.css' %}" type="text/css" rel="stylesheet">
    <link href="{% static 'smErp/assets/dropzone/dropzone.min.css' %}" type="text/css" rel="stylesheet">

{% endblock %}

{% block content %}
    <div class="inner wrp">
        <div class="page_nav">
            <a href="javascript:void(0);" class="jsUrlLink" data-url="home/index" target="_self">首页</a>
            <span class="gap">/</span>
            忘记密码
        </div>

        <div class="container_box cell_layout">
            <div class="forget_box type" id="step1">
                <form class="form" id="form" novalidate="novalidate">
                    {% csrf_token %}
                    <fieldset class="frm_fieldset last">
                        <legend class="frm_legend">请输入您的帐号</legend>
                        <div class="frm_control_group">
                            <div class="frm_controls">
                                <div class="frm_inner_controls">
                                    <div class="frm_inner_controls_hd">
                                        <label class="frm_radio_label selected">
                                            <span class="lbl_content">邮箱帐号</span>
                                        </label>
                                    </div>
                                    <div class="frm_inner_controls_bd" id="email-box">
                                        <div class="frm_control_group">
                                            <div class="frm_controls">
                                                <span class="frm_input_box">
                                                    <input id="email" name="email" class="frm_input valid" type="text"></span>
                                                <p class="frm_tips">请填写您的绑定邮箱地址</p>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </fieldset>
                    <div class="tool_bar with_form border">
                        <a href="javascript:" class="btn btn_primary" id="okBt">确定</a>
                    </div>
                </form>
            </div>
            <div class="forget_box" style="display: none;" id="step2">
                <div class="page_msg default simple">
                    <div class="inner">
                        <span class="msg_icon_wrp"><i class="icon_msg mail"></i></span>
                        <div class="msg_content">
                            <h4>密码重置邮件已发送至你的注册邮箱 : <span id="emailTxt"></span></h4>
                            <p>请访问邮件中给出的网页链接，根据页面提示完成密码重置。</p>
                            <p class="spacing">
                                <a href="javascript:void(0);" id="goEmail" class="btn btn_primary">登录邮箱</a>
                            </p>
                            <p>没有收到邮件？</p>
                            <ul>
                                <li>
                                    1. 请检查邮箱地址是否正确，你可以返回
                                    <a class="unline-a" href="javascript:;" id="rewrite">重新填写</a>
                                </li>
                                <li>2. 检查你的邮件垃圾箱</li>
                                <li>
                                    3. 若仍未收到确认，请尝试
                                    <a class="unline-a" href="javascript:;" id="reSend">重新发送</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block footscript %}
    <script>
        // 重新填写
        $("#rewrite").on("click", function(){
            $("#emailTxt").html("");
            $("#step2").hide();
            $("#step1").show();
        });
        // 登录邮箱
        $("#goEmail").on("click", function(){
            var url = "http://mail." + $("#email").val().split('@')[1];
            window.open(url);
        });
        // 请求下发忘记密码邮件
        $("#okBt").on("click", function(){
            var email = $("#email").val();
            if(!email){
                layer.msg("请输入邮箱地址");
                return;
            }else{
                if(!check_email(email)){
                   layer.msg("请输入正确格式的邮箱地址");
                    return;
                }
            }
            var params = $("#form").serialize();
            $.ajax({
                type: 'POST',
                url: '{% url "smErp:forget_password" %}',
                data: params,
                dataType: 'json',
                success: function(data){
                    if (data.result == 0) {
                        // 成功显示成功
{#                        layer.msg("重新发送邮件成功");#}
                        $("#emailTxt").html(email);
                        $("#step1").hide();
                        $("#step2").show();
                    } else {
                        //提示层
                        layer.msg(data.reason);
                    }
                }
            });
        });
    </script>
{% endblock %}




